package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.ProductDir;
import cn.wolfcode.trip.base.mapper.ProductDirMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IProductDirService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Copyright: Copyright (c) 2019 Super520
 * 描述：商品类型业务层接口
 *
 * @package: cn.wolfcode.trip.base.service.impl
 * @author: Patch
 * @date: 2019/5/31 21:46
 * 总结:
 */
@Service
public class ProductDirServiceImpl implements IProductDirService {
    @Autowired
    private ProductDirMapper dirMapper;
    @Override
    public void saveOrUpdate(ProductDir dir) {
        if (dir.getId() != null) {
            dirMapper.updateByPrimaryKey(dir);
        }else {
            // 添加的商品类型
            dirMapper.insert(dir);
        }
    }

    @Override
    public PageInfo<ProductDir> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize(), qo.getOrderBy());
        List<ProductDir> list = dirMapper.selectForList(qo);
        return new PageInfo<>(list);
    }

    @Override
    public List<ProductDir> listAll() {
        return dirMapper.selectAll();
    }

    @Override
    public List<ProductDir> listByParentId(Long parentId) {
        return dirMapper.listByParentId(parentId);
    }

    @Override
    public List<ProductDir> listParentAll() {
        return dirMapper.listParentAll();
    }
}
